package Application.Summoner;

import Application.Config.Config;
import Application.Exceptions.AppExceptions;
import Application.Util.StaticUtil;
import Application.MainMenu;
import Application.MethodObject.DefGuns;
import Application.Others.FunnyJoke;
import Application.Widgets.ErrorReportWidget;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

public class GunsSummoner
{
    public static void GunSummoner()
    {
        DefGuns def = new DefGuns();
        Config configs = Config.configReader();
        FunnyJoke funnyJoke = new FunnyJoke();
        String[] nope = new String[1];
        nope[0] = "null";

        StaticUtil.summonerFrame = new JFrame();
        JFrame mainFrame = StaticUtil.summonerFrame;
        mainFrame.setTitle("边缘世界ModXAML生成器");
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        mainFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);

        ErrorReportWidget.errorReport.setLineWrap(true);
        ErrorReportWidget.errorReport.setFont(configs.fontGetter());
        ErrorReportWidget.errorReport.setBackground(Color.BLACK);
        ErrorReportWidget.errorReport.setForeground(Color.RED);
        ErrorReportWidget.errorReport.setSelectionColor(Color.BLUE);
        JScrollPane scrollPane_1 = new JScrollPane(ErrorReportWidget.errorReport);
        scrollPane_1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        scrollPane_1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        JButton funnyJokes = new JButton("看看笑话");
        funnyJokes.setFont(configs.fontGetter());
        funnyJokes.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                ErrorReportWidget.errorReport.append(funnyJoke.getJokes_1() + "\n" + "笑话来源于网络\n");
            }
        });

        JPanel mainPanel = new JPanel();
        BoxLayout Box_Y = new BoxLayout(mainPanel, BoxLayout.Y_AXIS);
        mainPanel.setLayout(Box_Y);
        JPanel errPanel = new JPanel();
        BoxLayout Box_x = new BoxLayout(errPanel, BoxLayout.X_AXIS);
        errPanel.setLayout(Box_x);
        errPanel.setBackground(Color.BLACK);
        JMenuBar mainMenuBar = new JMenuBar();
        JMenu mainMenu = new JMenu("选项");
        JMenu mn_fontSetter = new JMenu("字体");
        JMenuItem mi_fontSetter_MS_Song = new JMenuItem("宋体");
        JMenuItem mi_fontSetter_Imitation_Song_Dynasty = new JMenuItem("仿宋");
        JMenuItem mi_backMainMenu = new JMenuItem("返回主菜单");
        JMenuItem mi_close = new JMenuItem("关闭");

        JScrollPane scrollPane_2 = new JScrollPane(mainPanel);
        scrollPane_2.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        scrollPane_2.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

        mi_fontSetter_MS_Song.setFont(configs.font_1);
        mi_fontSetter_MS_Song.addActionListener(e -> {
            try {
                configs.fontNumSetter(0);
                Config.configWriter(configs);
            } catch (AppExceptions ex) {
                String err = ex.ErrGetter();
                ErrorReportWidget.errorReport.append(err + "\n");
            }
        });
        mn_fontSetter.add(mi_fontSetter_MS_Song);
        mi_fontSetter_Imitation_Song_Dynasty.addActionListener(e -> {
            try {
                configs.fontNumSetter(1);
                Config.configWriter(configs);
            } catch (AppExceptions ex) {
                String err = ex.ErrGetter();
                ErrorReportWidget.errorReport.append(err + "\n");
            }
        });
        mi_fontSetter_Imitation_Song_Dynasty.setFont(configs.font_2);
        mi_backMainMenu.setFont(configs.fontGetter());
        mi_backMainMenu.addActionListener(e -> {
            mainFrame.setVisible(false);
            StaticUtil.mainMenuFrame = null;
            MainMenu.main(nope);
            return;
        });
        mn_fontSetter.add(mi_fontSetter_Imitation_Song_Dynasty);
        mn_fontSetter.setFont(configs.fontGetter());
        mainMenu.add(mn_fontSetter);
        mainMenu.add(mi_backMainMenu);
        mainMenu.add(mi_close);
        mainMenu.setFont(configs.fontGetter());
        mi_close.setFont(configs.fontGetter());
        mi_close.addActionListener(e -> System.exit(0));
        mainMenuBar.add(mainMenu);

        JLabel lab_XAMLName = new JLabel("请键入文件名称");
        lab_XAMLName.setFont(configs.fontGetter());

        JTextArea tf_XAMLName = new JTextArea(1, 5);
        tf_XAMLName.setLineWrap(true);
        tf_XAMLName.setFont(configs.fontGetter());

        JLabel lab_bullet_ParentName = new JLabel("请键入文件名称");
        lab_bullet_ParentName.setFont(configs.fontGetter());

        JTextArea tf_bullet_ParentName = new JTextArea(1, 20);
        tf_bullet_ParentName.setLineWrap(true);
        tf_bullet_ParentName.setFont(configs.fontGetter());

        mainPanel.add(lab_XAMLName);
        mainPanel.add(tf_XAMLName);
        mainPanel.add(lab_bullet_ParentName);
        mainPanel.add(tf_bullet_ParentName);
        mainPanel.add(funnyJokes);
        errPanel.add(scrollPane_1, BorderLayout.WEST);

        mainFrame.setSize(1200, 500);
        mainFrame.add(scrollPane_2, BorderLayout.CENTER);
        mainFrame.add(errPanel, BorderLayout.EAST);
        mainFrame.setJMenuBar(mainMenuBar);
        mainFrame.setVisible(true);
    }
}
